package com.elinkway.infinitemovies.share;


import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.ShareContent;
import com.elinkway.infinitemovies.utils.UIs;
import com.le123.ysdq.R;
import com.umeng.socialize.bean.SHARE_MEDIA;


public class ShareCommonPopWindow  implements OnClickListener{
    private RelativeLayout share2Qzone;
    private RelativeLayout share2Friends;
    private RelativeLayout share2Wechat;
    private RelativeLayout share2Weibo;
    private RelativeLayout cancelIv;
    private TextView titleTv;
    private ShareContent mShareContent;

    private Activity mContext;
    private Dialog mShareDialog;

    public ShareCommonPopWindow(Activity activity) {
        mContext = activity;
        View contentView = UIs.inflate(activity, R.layout.common_share_dialog, null);
        share2Qzone = (RelativeLayout) contentView.findViewById(R.id.qqshare);
        share2Friends = (RelativeLayout) contentView.findViewById(R.id.friendshare);
        share2Wechat = (RelativeLayout) contentView.findViewById(R.id.weixinshare);
        share2Weibo = (RelativeLayout) contentView.findViewById(R.id.sinashare);
        titleTv = (TextView) contentView.findViewById(R.id.title_tv);
        titleTv.setText("分享");
        cancelIv = (RelativeLayout) contentView.findViewById(R.id.right_close_iv);
        share2Qzone.setOnClickListener(this);
        share2Friends.setOnClickListener(this);
        share2Weibo.setOnClickListener(this);
        cancelIv.setOnClickListener(this);
        share2Wechat.setOnClickListener(this);
        mShareDialog = new Dialog(mContext, R.style.share_dialog);
        mShareDialog.setCancelable(true);
        mShareDialog.setCanceledOnTouchOutside(true);
        mShareDialog.setContentView(contentView);
        }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.qqshare:
                ShareUtils.shareToThird(mContext, mShareContent, SHARE_MEDIA.QQ);
                break;
            case R.id.sinashare:
                ShareUtils.shareToThird(mContext, mShareContent, SHARE_MEDIA.SINA);
                break;
            case R.id.weixinshare:
                ShareUtils.shareToThird(mContext, mShareContent, SHARE_MEDIA.WEIXIN);
                break;
            case R.id.friendshare:
                ShareUtils.shareToThird(mContext, mShareContent, SHARE_MEDIA.WEIXIN_CIRCLE);
                break;
            case R.id.right_close_iv:
                dismiss();
                break;
        }

    }

    public void show() {
        mShareDialog.show();
        mShareDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        mShareDialog.getWindow().setGravity(Gravity.BOTTOM);
    }
    public void dismiss() {
        if(mShareDialog.isShowing()){
            mShareDialog.dismiss();
        }
    }

    public void setShareContent(ShareContent mShareContent) {
        this.mShareContent = mShareContent;
    }
}
